#include "DialogManager.h"
#include "Stage.h"

DialogManager::DialogManager(){
}

void DialogManager::init(){
	m_pgeode = new osg::Geode();

	// Text box
	m_pbox = new osg::Geometry;

	osg::ref_ptr<osg::Vec3Array> rec = new osg::Vec3Array;
	rec->push_back(osg::Vec3d(20.,20.,-1.));
	rec->push_back(osg::Vec3d(20.,120.,-1.));
	rec->push_back(osg::Vec3d(1000.,120.,-1.));
	rec->push_back(osg::Vec3d(1000.,20.,-1.));
	m_pbox->setVertexArray(rec);

	osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
	colors->push_back(osg::Vec4d(1.,1.,1.,0.8));
	m_pbox->setColorArray(colors);
	m_pbox->setColorBinding(osg::Geometry::BIND_OVERALL);

	m_pbox->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));

	osg::ref_ptr<osg::StateSet> stateset = m_pbox->getOrCreateStateSet();
	stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
	stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
	stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

	// Text
	std::string timesFont("../data/fonts/arial.ttf");

	m_ptext = new osgText::Text();
    m_pgeode->addDrawable( m_ptext );

    m_ptext->setFont(timesFont);
	m_ptext->setPosition(osg::Vec3d(40.0,60.0,0.0));
	m_ptext->setCharacterSize(30.0);
	m_ptext->setColor(osg::Vec4d(0.0,0.0,0.0,1.0));

	StageManager::getInstance().getCurrentStage()->getHud()->getCamHud()->addChild(m_pgeode);
}

void DialogManager::clear(){
}

void DialogManager::displayText(std::string text) {
	m_pgeode->addDrawable(m_pbox);
	m_ptext->setText(text); 
}
	 
void DialogManager::removeText() {
	m_pgeode->removeDrawable(m_pbox);
	m_ptext->setText(""); 
}